#!/bin/bash
#
#DST Server Startup Script
#$1 : {{SERVER_PORT}}
#$2 : {{SERVER_TOKEN}}
#$3 : {{MAX_PLAYERS}}
#$4 : [IS ENDUP] ? 1 : 0

${SERVER_PORT} = $1
${SERVER_TOKEN} = $2
${MAX_PLAYERS} = $3

#ENDUP SCRIPT
if [ "$4" == "0" ]
then
    echo $1
    exit 0
fi

#TOKEN
echo "$1" > ./DoNotStarveTogether/config/server/cluster_token.txt

cd bin
#CAVE SERVER
coproc caves ( ./dontstarve_dedicated_server_nullrenderer -console -persistent_storage_root /home/container/DoNotStarveTogether -conf_dir config -cluster server -players ${MAX_PLAYERS} -shard Caves )
#MASTER SERVER
./dontstarve_dedicated_server_nullrenderer -bind_ip 0.0.0.0 -port {{SERVER_PORT}}  -console -persistent_storage_root /home/container/DoNotStarveTogether -conf_dir config -cluster server -players {{MAX_PLAYERS}} -shard Master